package com.ltx.blog_bam.controller;

import com.alibaba.fastjson.JSONObject;
import com.ltx.blog_bam.entity.dto.BlogInfo;
import com.ltx.blog_bam.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BlogController {

    @Autowired
    private BlogService blogService;
    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/GetCheckBlogInfo")
    public List<BlogInfo> GetCheckBlogInfo(){
       return blogService.CheckBlogInfo();
    }

    @PostMapping("/pass")
    public void pass(@RequestBody JSONObject param){
        Integer blogId = param.getInteger("blogId");
        redisTemplate.opsForList().remove("Check_blog",0,blogId);
        int passNum = (int) redisTemplate.opsForValue().get("passNum");
        redisTemplate.opsForValue().set("passNum",++passNum);
    }

    @PostMapping("/nopass")
    public void NoPass(@RequestBody JSONObject param){
        Integer blogId = param.getInteger("blogId");
        redisTemplate.opsForList().remove("Check_blog",0,blogId);
        int nopassNum = (int) redisTemplate.opsForValue().get("nopassNum");
        redisTemplate.opsForValue().set("nopassNum",++nopassNum);
        blogService.delBlog(blogId);
    }

}
